/* 
 * Keyed set data structure.
 * Copyright (C) 2006 Bob Zimmermann <rpz@cse.wustl.edu>
 *
 *  This file is a part of BAT.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * keyed_set.h
 *
 * Maintains a set of objects and performs standard operations on them.
 *
 * $Id: keyed_set.h 1409 2006-09-20 20:30:33Z rpz $
 *
 */

#ifndef KEYED_SET_H
#  define KEYED_SET_H

#  include<stdio.h>
#  include<stdlib.h>
#  include<string.h>
#  include "darray.h"
#include "mem.h"

/* !!!XXX!!! problem -- no deleting */
typedef void *(*keyed_set_copy_op) (const void *);
typedef void (*keyed_set_delete_op) (void *, int);

typedef da_pos_t ks_pos_t;

typedef struct _keyed_set_ops_t
{
  keyed_set_copy_op copy;
  keyed_set_delete_op delete;
} keyed_set_ops_t;

keyed_set_ops_t *keyed_set_ops_new (keyed_set_copy_op copy, keyed_set_delete_op delete);
keyed_set_ops_t *keyed_set_ops_copy (const keyed_set_ops_t * kso);
void keyed_set_ops_delete (keyed_set_ops_t * kso, int );

typedef struct _keyed_set_t
{
  darray_t *inds;
  darray_t *set;
} keyed_set_t;

keyed_set_t *keyed_set_new (ks_pos_t init_size, keyed_set_ops_t * kso);
keyed_set_t *keyed_set_copy (const keyed_set_t * ks);
void keyed_set_delete (keyed_set_t * ks, int );
void keyed_set_add (keyed_set_t * ks, void *data, ks_pos_t id);
void *keyed_set_get (keyed_set_t * ks, ks_pos_t id);
void keyed_set_set (keyed_set_t * ks, ks_pos_t id, void *data);
darray_t *keyed_set_get_darray (keyed_set_t * ks);

#endif /* KEYED_SET_H */
